package beans;

import libs.UserValidation;

import bookException.BookException;
import bookException.BookExceptionCode;

import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing.Validation;

import classes.AddClass;
import entity.User;

public class AddBean extends GeneralBean{

	private AddClass addClass;
	
	public AddBean() {
		 this.addClass = new AddClass();
	}
	
	public User getPerson(){
		User user = new User();
		user.setName(getStringFromParam("tbName"));
		user.setSurname(getStringFromParam("tbSurname"));
		user.setMiddlename(getStringFromParam("tbMiddlename"));
		user.setMobile(getStringFromParam("tbMobile"));
		user.setPhonehome(getStringFromParam("tbHomephone"));
		user.setAddress(getStringFromParam("tbAddress"));
		user.setMail(getStringFromParam("tbMail"));
		return user;
	}
	
	public boolean getAddperson() {
		User user = new User();
		user.setName(getStringFromParam("tbName"));
		user.setSurname(getStringFromParam("tbSurname"));
		user.setMiddlename(getStringFromParam("tbMiddlename"));
		user.setMobile(getStringFromParam("tbMobile"));
		user.setPhonehome(getStringFromParam("tbHomephone"));
		user.setAddress(getStringFromParam("tbAddress"));
		user.setMail(getStringFromParam("tbMail"));
		try {
			UserValidation.validateUser(user);
		} catch (BookException e) {
			this.setBookException(e);
			return false;
		}
		addClass.addPerson(user);
		return true;
	}
}
